package com.shujia.redis;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;


public class Demo2Cluster {
    public static void main(String[] args) {


        //连接池配置
        JedisPoolConfig poolConfig = new JedisPoolConfig();

        //最大连接数据
        poolConfig.setMaxTotal(1);
        //最大空闲连接数据
        poolConfig.setMaxIdle(1);

        //超时时间
        poolConfig.setMaxWaitMillis(1000);


        HashSet<HostAndPort> nodes = new HashSet<>();

        nodes.add(new HostAndPort("node1", 7000));
        nodes.add(new HostAndPort("node1", 7001));
        nodes.add(new HostAndPort("node1", 7002));
        nodes.add(new HostAndPort("node1", 7003));
        nodes.add(new HostAndPort("node1", 7004));
        nodes.add(new HostAndPort("node1", 7005));

        //创建连接
        JedisCluster jedisCluster = new JedisCluster(nodes, 1000, 2000, 1, "123456", poolConfig);

        String a = jedisCluster.get("a");
        System.out.println(a);
    }
}
